import Router from 'koa-router';
import { config } from '../config';
import authRoutes from './auth.routes';
import userRoutes from './user.routes';
import articleRoutes from './article.routes';
import categoryRoutes from './category.routes';
import tagRoutes from './tag.routes';
import commentRoutes from './comment.routes';
import uploadRoutes from './upload.routes';
import searchRoutes from './search.routes';

// 创建路由实例
const router = new Router({
  prefix: config.server.apiPrefix
});

// 健康检查
router.get('/health', (ctx) => {
  ctx.body = {
    status: 'success',
    message: 'API服务正常',
    timestamp: new Date(),
    env: config.env
  };
});

// 注册子路由
router.use('/auth', authRoutes.routes(), authRoutes.allowedMethods());
router.use('/users', userRoutes.routes(), userRoutes.allowedMethods());
router.use('/articles', articleRoutes.routes(), articleRoutes.allowedMethods());
router.use('/categories', categoryRoutes.routes(), categoryRoutes.allowedMethods());
router.use('/tags', tagRoutes.routes(), tagRoutes.allowedMethods());
router.use('/comments', commentRoutes.routes(), commentRoutes.allowedMethods());
router.use('/upload', uploadRoutes.routes(), uploadRoutes.allowedMethods());
router.use('/search', searchRoutes.routes(), searchRoutes.allowedMethods());

export default router; 